package com.axend.aerosense.common.connect.ble.handler;

import com.axend.aerosense.common.connect.bean.BleMsgEntity;
import com.axend.aerosense.common.connect.bean.BleMsgTag;
import com.axend.aerosense.common.connect.bean.BleNotifyEntity;
import com.axend.aerosense.common.connect.ble.AbstractBleMsgProcessor;
import com.blankj.utilcode.util.LogUtils;

/**
 * 蓝牙设置状态处理器（通讯板）
 */
public class BleSetStateHandler extends AbstractBleMsgProcessor {

    //设置成功
    public static final byte SET_SUCCESS = 0x01;
    //设置失败
    public static final byte SET_FAILED = 0x00;

    @Override
    protected BleMsgTag getMsgTag() {
        return BleMsgTag.SET_STATUS;
    }

    @Override
    public byte[] write(BleMsgEntity bleMsgEntity) {
        return new byte[0];
    }

    @Override
    public BleNotifyEntity processor(BleNotifyEntity notifyEntity) {
        if (null == notifyEntity) {
            LogUtils.w("notifyEntity is null");
            return null;
        }

        byte[] bytes = (byte[]) notifyEntity.getData();

        if (isNull(bytes)) {
            LogUtils.w("bytes length 0");
            return null;
        }

        boolean status = bytes[0] == SET_SUCCESS;
        return new BleNotifyEntity(getMsgTag(), status);
    }
}
